import yaml
from types import SimpleNamespace
from argparse import Namespace

def reader(path: str):
    with open(path, 'r', encoding='utf-8') as file:
        config_dict = yaml.safe_load(file)
    
    class Config(Namespace):
        def __init__(self, **kwargs):
            super().__init__(**kwargs)
        
        def __getitem__(self, key):
            return getattr(self, key)
        
        def __setitem__(self, key, value):
            setattr(self, key, value)
        
        def __contains__(self, key):
            return hasattr(self, key)
        
        def get(self, key, default=None):
            return getattr(self, key, default)
        
        def keys(self):
            return vars(self).keys()
        
        def values(self):
            return vars(self).values()
        
        def items(self):
            return vars(self).items()
        
        def to_dict(self):
            return self._to_dict(self)
        
        def _to_dict(self, ns):
            if isinstance(ns, Namespace):
                return {k: self._to_dict(v) for k, v in vars(ns).items()}
            elif isinstance(ns, list):
                return [self._to_dict(item) for item in ns]
            else:
                return ns
    
    def dict_to_config(d):
        if isinstance(d, dict):
            return Config(**{k: dict_to_config(v) for k, v in d.items()})
        elif isinstance(d, list):
            return [dict_to_config(item) for item in d]
        else:
            return d
    
    return dict_to_config(config_dict)